
#include "itkQuadEdgeMesh.h"
#include "itkMeshFileReader.h"
#include "itkMeshFileWriter.h"

#include "itkQuadEdgeMeshExtendedTraits.h"
#include "itkDiscreteGaussianCurvatureQuadEdgeMeshFilter.h"
#include "itkDiscreteMeanCurvatureQuadEdgeMeshFilter.h"
using namespace std;

#define USAGE "Usage: CurvatureCalculator 1 2 \n"\
			  "where\n"\
			  "\t1. SPHARM file - Generated spherical model description of the object \n"\
			  "\t2. CurvatureMap - The corresponding curvature map\n"

// ./CurvatureCalculator SPHARM.vtk curvature1.vtk

int main( int argc, char* argv[] )
{
  if( argc < 2 )
    {
    cout <<"*** GaussianCurvature ***" <<endl;
    cout <<"This example requires at least one argument:" <<endl;
    cout <<" 1- FileName" <<endl;
    return EXIT_FAILURE;
    }

  const unsigned int Dimension = 3;
  typedef double CoordType;

  typedef itk::QuadEdgeMeshExtendedTraits <
    CoordType,
    Dimension,
    2,
    CoordType,
    CoordType,
    CoordType,
    bool,
    bool > Traits;

  typedef itk::QuadEdgeMesh< CoordType, Dimension, Traits > MeshType;
  typedef itk::DiscreteGaussianCurvatureQuadEdgeMeshFilter< MeshType, MeshType > CurvatureFilterType;
//  typedef itk::DiscreteMeanCurvatureQuadEdgeMeshFilter< MeshType, MeshType > CurvatureFilterType;
  typedef itk::MeshFileReader< MeshType > ReaderType;

  ReaderType::Pointer reader = ReaderType::New( );
  reader->SetFileName( argv[1] );
  try
    {
    reader->Update( );
    }
  catch( itk::ExceptionObject & excp )
    {
    cerr << "Exception thrown while reading the input file " << endl;
    cerr << excp << endl;
    return EXIT_FAILURE;

    }

  MeshType::Pointer mesh = reader->GetOutput();

  CurvatureFilterType::Pointer gaussian_curvature = CurvatureFilterType::New();
  gaussian_curvature->SetInput( mesh );
  gaussian_curvature->Update();

  MeshType::Pointer output = gaussian_curvature->GetOutput();

  typedef itk::MeshFileWriter< MeshType > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetInput( output );
  char* outputFile = argv[2];
  writer->SetFileName( outputFile );
  writer->Update();

  // ** PRINT **
  cout << gaussian_curvature;
  return EXIT_SUCCESS;
}
